package View;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import Controller.CtrlAjoutUtilisateur;
import Listener.LAjout;

public class PanneauSaisieUtilisateur extends JPanel {

	private static final long serialVersionUID = 1L;
	
	JPanel northPanel;
	JPanel southPanel;
	JPanel centerPanel;
	
	JPanel nameTextPanel;
	JPanel nameLabelPanel;
	
	JPanel loginLabelPanel;
	JPanel loginTextPanel;
	
	JPanel privilegeLabelPanel;
	JPanel privilegeTextPanel;
	
	JPanel loginSupLabelPanel;
	JPanel loginSupTextPanel;
	
	JPanel pwdLabelPanel;
	JPanel pwdTextPanel;
	
	JPanel mainPanel;
	
	JScrollPane mainScroller;
	
	GridLayout centerLayout;
	GridLayout mainLayout;
	
	JLabel title;
	JLabel loginLabel;
	JLabel nameLabel;
	JLabel privilegeLabel;
	JLabel loginSupLabel;
	JLabel pwdLabel;
	
	JTextField loginText;
	JTextField nameText;
	JTextField loginSupText;
	
	JPasswordField pwdText;
	
	JButton bAdd;
	
	JComboBox<String> privilegeComboB;
	
	CtrlAjoutUtilisateur _ctrl;
	
	public PanneauSaisieUtilisateur(CtrlAjoutUtilisateur ctrl)
	{
		_ctrl = ctrl;
		
		mainPanel = new JPanel();
		
		mainScroller = new JScrollPane(mainPanel);
		
		northPanel = new JPanel();
		southPanel = new JPanel();
		centerPanel = new JPanel();
		
		nameTextPanel = new JPanel();
		nameLabelPanel = new JPanel();
		
		loginTextPanel = new JPanel();
		loginLabelPanel = new JPanel();
		
		privilegeTextPanel = new JPanel();
		privilegeLabelPanel = new JPanel();
		
		loginSupTextPanel = new JPanel();
		loginSupLabelPanel = new JPanel();
		
		pwdTextPanel = new JPanel();
		pwdLabelPanel = new JPanel();
		
		title = new JLabel("<html><u>Ajout :</u></html>");
		
		loginLabel = new JLabel("Login : ");
		loginText = new JTextField(15);
		
		nameLabel = new JLabel("Nom : ");
		nameText = new JTextField(15);
		
		privilegeLabel = new JLabel("Privilège : ");
		privilegeComboB = new JComboBox<String>();
		
		loginSupLabel = new JLabel("Login supérieur : ");
		loginSupText = new JTextField(15);
		
		pwdLabel = new JLabel("Password : ");
		pwdText = new JPasswordField(15);
		
		bAdd = new JButton("Ajouter");
		
		centerLayout = new GridLayout(5, 2);
		
		mainLayout = new GridLayout(3,1);
		
		// Modifiying
		
		privilegeComboB.setPreferredSize(new Dimension(150,20));
		
		centerPanel.setLayout(centerLayout);
		
		privilegeComboB.addItem("Administrateur");
		privilegeComboB.addItem("Autre");
		
		// Adding to Window
		loginLabelPanel.add(loginLabel);
		loginTextPanel.add(loginText);
		
		nameLabelPanel.add(nameLabel);
		nameTextPanel.add(nameText);
		
		privilegeLabelPanel.add(privilegeLabel);
		privilegeTextPanel.add(privilegeComboB);
		
		loginSupLabelPanel.add(loginSupLabel);
		loginSupTextPanel.add(loginSupText);
		
		pwdLabelPanel.add(pwdLabel);
		pwdTextPanel.add(pwdText);
		
		
		northPanel.add(title);
		
		centerPanel.add(loginLabelPanel);
		centerPanel.add(loginTextPanel);
		centerPanel.add(nameLabelPanel);
		centerPanel.add(nameTextPanel);
		centerPanel.add(privilegeLabelPanel);
		centerPanel.add(privilegeTextPanel);
		centerPanel.add(loginSupLabelPanel);
		centerPanel.add(loginSupTextPanel);
		centerPanel.add(pwdLabelPanel);
		centerPanel.add(pwdTextPanel);
		
		southPanel.add(bAdd);
		
		mainPanel.setLayout(new BorderLayout());
		
		mainPanel.add(northPanel, BorderLayout.NORTH);
		mainPanel.add(centerPanel, BorderLayout.CENTER);
		mainPanel.add(southPanel, BorderLayout.SOUTH);
		
		this.setLayout(new BorderLayout());
		this.add(mainScroller, BorderLayout.CENTER);
		
		bAdd.addActionListener(new LAjout(_ctrl));

	}
	
	public String getLogin() {
		return loginText.getText();
	}
	
	public String getName() {
		return nameText.getText();
	}
	
	public String getPassword() {
		return new String(pwdText.getPassword());
	}
	
	public int getPrivilege() {
		return privilegeComboB.getSelectedIndex();
	}
	
	public String getSupLogin() {
		return loginSupText.getText();
	}
	

	
	public void clear() {
		loginText.setText("");
		nameText.setText("");
		privilegeComboB.setSelectedIndex(0);
		loginSupText.setText("");
		loginText.setText("");
		pwdText.setText("");
	}
}
